<template>
    <!-- <div>封堵白名单</div> -->
    <a-row>
      <a-col>
        <a-card :bordered="false" style="margin-bottom: 10px">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
            <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-row style="display:flex">
                <a-col :span="6">
                <a-form-model-item label="起止时间">
                    <a-range-picker v-model="time"/>
                </a-form-model-item>
              </a-col>
                  <a-col :span="6" style="margin-left:0px">
                    <a-space :size="6">
                      <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                      <a-button @click="onResetForm" icon="reload">重置</a-button>
                    </a-space>
                  </a-col>   
              </a-row>
            </a-form-model>
          </div>
        </a-card>
        <a-card :bordered="false">
          <div>
            <a-button type="primary" @click="Add" style="margin-right:10px">批量导出</a-button>
            <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
              :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
              <template slot="action">
                    <a-button type="link" @click="View">预览</a-button>
                    <a-button type="link" @click="Details">导出</a-button>
                    <a-button type="link" @click="Report">更新</a-button>
              </template>
              <template slot="generateIs" slot-scope="text, record">
                    <span v-if="text == 1">是</span>
                    <span v-if="text == 2">否</span>
              </template>
            </z-table>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </template>
  
  <script>
  import { pageNewAnalysisReport } from '@/api/plugging/Police'
  export default {
    mounted () {
      this.type = this.$route.query.type
      this.onQuery()
    },
    data () {
      return {
        time:[],
        type:'',
        show:false,
        labelCol: { span: 5 },
        wrapperCol: { span: 16 },
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        pageData: {},
        columns:[
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '报告日期',
            dataIndex: 'reportDate',
            align: 'center',
          },
          {
            title: '是否生成',
            dataIndex: 'generateIs',
            align: 'center',
            scopedSlots: { customRender: 'generateIs' },
          },
          {
            title: '更新时间',
            dataIndex: 'updateTime',
            align: 'center',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
          },

        ]
      }
    },
    methods: {
      View(){
        this.$router.push({
        path: '/plugging/police/Report/FraudView',
        query: {}
      })
      },
      Details(){
        this.$router.push({
        path: '/plugging/police/HandlUnseal/Details',
        query: {}
      })
      },
      Report(){
        this.$router.push({
        path: '/plugging/police/HandlUnseal/Report',
        query: {}
      })
      },
      onQuery() {
        this.pageFilter.pageNo = 1
        this.pageFilter.type = this.type
        let a = this.timestampToTime(this.time[0])
        let b = this.timestampToTime(this.time[1])
        this.pageFilter.startTime = a
        this.pageFilter.endTime = b
        this.refreshTable()
      },
      //重置
      onResetForm() {
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10,
          type:this.type
        }
        this.time = []
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        pageNewAnalysisReport(this.pageFilter).then( res => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
    },
    timestampToTime(timestamp) {
      if (timestamp === 0 || timestamp == null) {
        return ''
      } else {
        var date = new Date(Date.parse(timestamp))
        var Y = date.getFullYear() + '-'
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
        var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
        var H = date.getHours() + ':'
        var M2 = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
        var S = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
        return Y + M + D + H + M2 + S
      }
    }
    }
  }
  </script>
  
  <style lang="less" scoped>
  .search-wrapper-btn {
    position: absolute;
    right: 8%;
    top: 22px;
    z-index: 100;
  }
  </style>